﻿using System;
using Core;
using Norm;

namespace NoSQLDataProvider
{
    public class NoSQLRepositoryContext : IDisposable
    {
        private readonly IMongo _provider;

        public IMongo Provider
        {
            get { return _provider; }
        }

        public static string DatabaseName
        {
            get { return AppSettings.MongodbName; }
        }

        public IMongoDatabase DataBase
        {
            get
            {
                return _provider.Database;
            }
        }

        public NoSQLRepositoryContext()
        {
            if (string.IsNullOrEmpty(DatabaseName))
            {
                throw new InvalidOperationException("You must set the static DatabaseName property.");
            }
            _provider = Mongo.Create(DatabaseName);
        }

        public void Dispose()
        {
            _provider.Dispose();
        }
    }
}
